package com.healthcloud.service.impl;


import com.healthcloud.dao.TestProjectItemConclusionMapper;
import com.healthcloud.entity.TestProjectItemConclusion;
import com.healthcloud.service.TestProjectItemConclusionService;
import com.healthcloud.utils.PageParam;
import com.healthcloud.vo.TestProjectItemConclusionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by houxianghua on 2015/7/10.
 */
@Service
@Transactional
public class TestProjectItemConclusionServiceImpl implements TestProjectItemConclusionService {

    @Autowired
    private TestProjectItemConclusionMapper testProjectItemConclusionMapper;


    @Override
    public TestProjectItemConclusion get(int id) {
        return testProjectItemConclusionMapper.get(id);
    }

    @Override
    public List<TestProjectItemConclusion> findByEntityAll(TestProjectItemConclusion entity) {
        return testProjectItemConclusionMapper.findByEntityAll(entity);
    }

    @Override
    public List<TestProjectItemConclusionVo> search(TestProjectItemConclusionVo entity, PageParam pageParam) {
        return testProjectItemConclusionMapper.search(entity, pageParam);
    }

    @Override
    public int count(TestProjectItemConclusionVo entity) {
        return testProjectItemConclusionMapper.count(entity);
    }

    @Override
    public int save(TestProjectItemConclusion entity) {
        return testProjectItemConclusionMapper.save(entity);
    }

    @Override
    @Transactional
    public void saveBatch(List<TestProjectItemConclusion> entity) {
        List<TestProjectItemConclusion> addList = new ArrayList<>();
        List<TestProjectItemConclusion> updateList = new ArrayList<>();
        for (int i = 0; i < entity.size(); i++) {
            TestProjectItemConclusion testProjectItemConclusion = entity.get(i);
            if (testProjectItemConclusion.getId() == null) {
                addList.add(testProjectItemConclusion);
            } else {
                updateList.add(testProjectItemConclusion);
            }
        }
        if (addList.size() != 0) {
            testProjectItemConclusionMapper.saveBatch(addList);
        }
        for (int i = 0; i < updateList.size(); i++) {
            TestProjectItemConclusion testProjectItemConclusion = updateList.get(i);
            update(testProjectItemConclusion);
        }
    }

    @Override
    public int update(TestProjectItemConclusion entity) {
        return testProjectItemConclusionMapper.update(entity);
    }

    @Override
    public int delete(int id) {
        return testProjectItemConclusionMapper.delete(id);
    }

    @Override
    @Transactional
    public int deletes(int[] ids) {
        int j = 0;
        for (int i = 0; i < ids.length; i++) {
            j = delete(ids[i]);
        }
        return j;
    }
}
